/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author A0077454
 */
@Entity  
public class BankAccount implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long bankAccountId;
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private Bank bank;
    private String accountNum;
    private String accountType;
    private String accountOwner;
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private Currency currency;
    @OneToMany(cascade = {CascadeType.PERSIST}, mappedBy="bankAccount")
    private List<Transaction> transactions = new ArrayList();

    public BankAccount() {
    }

    public void create(String accountNum, String accountType, String accountOwner) {
       
        this.accountNum = accountNum;
        this.accountType = accountType;
        this.accountOwner = accountOwner;
    }

    public List<Transaction> getTransactions() {
        return transactions;
    }
    
    

    public void setTransactions(List<Transaction> transactions) {
        this.transactions = transactions;
    }

    
    
    public String getAccountNum() {
        return accountNum;
    }

    public void setAccountNum(String accountNum) {
        this.accountNum = accountNum;
    }

    public String getAccountOwner() {
        return accountOwner;
    }

    public void setAccountOwner(String accountOwner) {
        this.accountOwner = accountOwner;
    }

    public String getAccountType() {
        return accountType;
    }

    public void setAccountType(String accountType) {
        this.accountType = accountType;
    }

    public Bank getBank() {
        return bank;
    }

    public void setBank(Bank bank) {
        this.bank = bank;
    }

    public Long getBankAccountId() {
        return bankAccountId;
    }

    public void setBankAccountId(Long bankAccountId) {
        this.bankAccountId = bankAccountId;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }
    
    

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (bankAccountId != null ? bankAccountId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BankAccount)) {
            return false;
        }
        BankAccount other = (BankAccount) object;
        if ((this.bankAccountId == null && other.bankAccountId != null) || (this.bankAccountId != null && !this.bankAccountId.equals(other.bankAccountId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.BankAccount[ id=" + bankAccountId + " ]";
    }
    
    
    
    //// THINN CHANGES /////
    public void addTransaction(Transaction transaction)
    {
        this.transactions.add(transaction);
    }
    
}
